package online.takemehand.fx;

import javafx.application.Application;
import javafx.collections.ListChangeListener;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * group容器
 */
public class Main5 extends Application {


    @Override
    public void start(Stage primaryStage) throws Exception {

        Button buttonaa = new Button("aa");
        Button buttonbb = new Button("bb");
        Button buttoncc = new Button("cc");

        buttonaa.setLayoutX(0);
        buttonaa.setLayoutY(10);
        buttonaa.setCursor(Cursor.HAND);

        buttonbb.setLayoutX(100);
        buttonbb.setLayoutY(10);
        buttonbb.setCursor(Cursor.HAND);

        buttoncc.setLayoutX(200);
        buttoncc.setLayoutY(10);
        buttoncc.setCursor(Cursor.HAND);

        Group group = new Group();
        group.getChildren().add(buttonaa);
        group.getChildren().add(buttonbb);
        group.getChildren().add(buttoncc);


        group.getChildren().addListener(new ListChangeListener<Node>() {
            @Override
            public void onChanged(Change<? extends Node> c) {
                System.out.println(c.getList().size());
            }
        });



        buttonaa.setOnMouseClicked(event -> {

            Button buttondd = new Button("dd");
            group.getChildren().add(buttondd);
        });



        group.setOpacity(0.5);

        System.out.println(group.contains(0, 10));
        System.out.println(group.contains(0, 20));


        Scene scene = new Scene(group, 600, 400);
        primaryStage.setScene(scene);
        primaryStage.show();


    }
}
